home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6926 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: beach.and.nl!usenet
  2. From: jos@and.nl (Jos A. Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: ERR with typedef...lvalue
  5. Date: 16 Feb 1996 10:35:14 GMT
  6. Organization: AND Operations Research B.V.
  7. Message-ID: <4g1ml2$ibo@beach.and.nl>
  8. References: <1996Feb15.190109@nyssa.swt.edu>
  9. NNTP-Posting-Host: klepzeiker.and.nl
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <1996Feb15.190109@nyssa.swt.edu>, kv09845@nyssa.swt.edu wrote:
  15.  
  16. |The following is a program I can't seem to get to compile. It keeps giving me
  17. |an error. Would anyone happen to know why. I'm sure it's simple, but then, so
  18. |am I. Any help greatly appreciated.
  19.  
  20. [ just the essentials: ]
  21.  
  22. |    typedef char STRING[81];
  23. |
  24. |    STRING text, input_line;
  25. |
  26. |    text = "this is the text string";
  27. |    input_line = "this is the input_line string";
  28.  
  29. [ the compiler diagnostics: ]
  30.  
  31. |            683     text = "this is the text string";
  32. |                ....1                                 
  33. |%CC-E-NEEDLVALUE, (1) In this statement, "text" is not an lvalue, but occurs 
  34. |in a context that requires one.
  35. |
  36. |            684     input_line = "this is the input_line string";
  37. |                ....1                                             
  38. |%CC-E-NEEDLVALUE, (1) In this statement, "input_line" is not an lvalue, but 
  39. |occurs in a context that requires one.
  40.  
  41. I love your compiler; I just love its verbose way of communicating with
  42. its user: In this statement, "input_line" is not an lvalue, but occurs
  43. in a context that requires one. And ever so right it is: the variables
  44. 'input_line' and 'text' are not (modifiable) lvalues; they're both just
  45. a bunch (an array) of modifiable lvalues. 
  46.  
  47. The left hand side of an expression operator needs a modifiable lvalue
  48. (some object that can be assigned to). C is just a simple language; 
  49. there is no way one can assign multiple values to multiple modifiable
  50. lvalues in one sweep unless the collection of those lvalues happens
  51. to be an lvalue itself (e.g. structure assigments). 
  52.  
  53. A tedious way of solving this little problem is:
  54.  
  55.     input_line[0]= 't';
  56.     input_line[1]= 'h';
  57.     input_line[2]= 'i';
  58.     /* etc. etc. */
  59.  
  60. but a nicer way of putting it is:
  61.  
  62.     strcpy(input_line, "this is the input_line string");
  63.  
  64. There's another solution though: if you want to initialize both
  65. STRINGs, there's no need to assign them afterwards:
  66.  
  67.     STRING input_line = "this is the input_line string";
  68.  
  69. Note that this is not an assignment, it's an initialization, performed
  70. before the process starts running if the variables happen to be global
  71. objects or performed by some nitty-gritty code inserted by the compiler
  72. for you if those objects are local to some function.
  73.  
  74. kind regards,
  75.  
  76. Jos aka jos@and.nl (still ashamed about that nasty 1000! problem ;-)
  77. -- 
  78. Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
  79.  
  80.